<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>条件渲染</title>
</head>
<body>
  <div id="app"></div>
  <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
  <!-- 使用jsx需要babel转义 -->
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <!-- 使用babel需要申明type -->
  <script type="text/babel">
    const tag = document.getElementById('app')
    function As(props) {
      return <div onClick={props.onClick}>你好，欢迎xxx</div>
    }
    function Bs(props) {
      return <div onClick={props.onClick}>退出登录</div>
    }
    class Par extends React.Component{
      constructor(props) {
        super(props)
        this.state= {
          isLogin: true
        }
        this.login = this.login.bind(this)
        this.logout = this.logout.bind(this)
      }
      login() {
        console.log('登录')
        this.setState({
          isLogin: true
        })
      }
      logout() {
        console.log('登出')
        this.setState({
          isLogin: false
        })
      }
      render() {
        let { isLogin } = this.state
        let btn = isLogin? <button onClick={ this.logout }>登出</button> : <button onClick={ this.login }>登录</button>
        // let btn = <button>登出</button>
        return (
          <div>
          {isLogin? <As /> :<Bs /> }
          
          {btn}
          </div>
          )
      }
    }
    ReactDOM.render(
      <Par />,
      tag
    )
  </script>
</body>
</html>